<template>
	<view class="My">
		<cu-custom bgColor="HomePageStyle">
			<block slot="content">姚记潮品订货</block>
		</cu-custom>
		<view class="NameAndAvatarArea" @click="toLogin">
			<view class="Avatar">
				<img :src="userInfo.avatarUrl" alt="" class="avatar" />
			</view>
			<view class="Name">
				<view class="NoLogin" v-if="!LoginOrNot">
					<view class="MainTitle">您尚未登录</view>
					<view class="SubTitle"> 点击下方登录/注册 </view>
				</view>
				<view class="Login" v-else>
					<!-- <view class="Phone">{{ MyInfoDetalis.phone }}</view> -->
					<view class="name">{{ userInfo.nickName }}</view>
				</view>
			</view>
		</view>
		<view class="profile">
			<view class="list" @click="toOrder" v-if="userInfo.type&&userInfo.type===20">
				<view class="left">我的订单</view>
				<view class="right">
					<view class="content"></view>
					<view class="icon">
						<img :src="imgUrl + 'Jt.png'" class="jt" alt="" />
					</view>
				</view>
			</view>
			<view class="list" @click="toShopCard" v-if="userInfo.type&&userInfo.type===20">
				<view class="left">购物车</view>
				<view class="right">
					<view class="content"></view>
					<view class="icon">
						<img :src="imgUrl + 'Jt.png'" class="jt" alt="" />
					</view>
				</view>
			</view>
			<view class="list" @click="ToAddress" v-if="userInfo.type&&userInfo.type===20">
				<view class="left">收货地址</view>
				<view class="right">
					<view class="content"></view>
					<view class="icon">
						<img :src="imgUrl + 'Jt.png'" class="jt" alt="" />
					</view>
				</view>
			</view>
			<view class="list" @click="toInformation" v-if="userInfo.type&&userInfo.type===20">
				<view class="left">店铺资料</view>
				<view class="right">
					<view class="content"></view>
					<view class="icon">
						<img :src="imgUrl + 'Jt.png'" class="jt" alt="" />
					</view>
				</view>
			</view>
			<view class="list">
				<view class="left">商家公告</view>
				<view class="right">
					<view class="content"></view>
					<view class="icon">
						<!-- <img :src="imgUrl + 'Jt.png'" class="jt" alt="" /> -->
					</view>
				</view>
			</view>
			<view class="list last">
				<view class="left last">关于姚记潮品 订货商城</view>
				<view class="right last">
					<view class="content">2.12.320</view>
				</view>
			</view>

		</view>

		<view class="PhoneLogin" @click="del" v-if="LoginOrNot"> 退出登录 </view>
	</view>
</template>

<script>
	import gameDetails from "@/static/lib/public.js";
	import {
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				token: "",

				LoginOrNot: "",

				gameDetailsData: gameDetails,

				imgUrl: this.$http.imgUrl + '/static/my/',

				userInfo: {},

				avatar: "",

				show: true
			};
		},

		created() {
			this.LoginOrNot = this.IsLogin();
			if (this.LoginOrNot) {
				this.getUserInfo();
			}
		},
		methods: {
			...mapMutations('user', ['setUserInfo']),
			toLogin() {
				if (!this.LoginOrNot) {
					uni.navigateTo({
						url: "/pages/login/login",
					});
				} else {
					uni.navigateTo({
						url: "/pagesA/My/EditUserInfo",
					});
				}
			},
			ToAddress() {
				uni.navigateTo({
					url: "/pagesA/My/Address",
				});
			},
			async getUserInfo() {
				const url = this.api.my.getUserInfo;
				const res = await this.$http.get(url);
				// console.log(res, "获取个人信息");
				this.userInfo = res.data.data;
				// this.$store.commit('user/setUserInfo',res)
				this.setUserInfo(res.data.data)
				// uni.setStorageSync("MyInfoDetalis", res);
			},
			// 去订单页面
			toOrder() {
				uni.navigateTo({
					url: '/pages/Order/Order'
				})
			},
			// 去购物车页面
			toShopCard() {
				uni.navigateTo({
					url: '/pagesA/My/shoppingCard'
				})
			},
			// 去店铺资料
			toInformation() {
				uni.navigateTo({
					url: '/pagesA/My/information?id=' + this.userInfo.shopId
				})
			},
			// 退出登录
			del() {
				uni.showModal({
					content: '确定退出登录吗?',
					success: (res) => {
						if (res.confirm) {
							uni.removeStorageSync('token')
							uni.removeStorageSync('userInfo')
							uni.reLaunch({
								url:'/pages/index/index?id=HomePage'
							})
						}
					}

				})
			}
		},
	};
</script>

<style lang="scss" scoped>
	.My {
		position: relative;
		height: 100vh;

		.NameAndAvatarArea {
			width: 100%;
			height: 200rpx;
			display: flex;
			background-color: #4d86f6;
			align-items: center;

			.Avatar {
				width: 100rpx;
				height: 100rpx;
				background-color: #FFFFFF;
				border-radius: 50%;
				margin-left: 30rpx;

				.avatar {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.Name {
				display: flex;
				align-items: center;

				.NoLogin {
					margin-left: 20rpx;
					margin-top: 10rpx;
					color: #FFFFFF;

					.MainTitle {
						font-size: 32rpx;
						margin-bottom: 10rpx;
					}

					.SubTitle {
						font-size: 25rpx;
						font-weight: 400;
					}
				}

				.Login {
					margin-left: 20rpx;

					.name {
						color: #FFFFFF;
					}
				}
			}
		}

		.jt {
			width: 10rpx;
			height: 20rpx;
		}

		.profile {
			width: 95%;
			margin: 0 auto;
			margin-top: -3%;
			background: #FFFFFF;
			border-radius: 35rpx;

			.list {
				height: 100rpx;
				display: flex;
				align-items: center;
				border-bottom: 3rpx solid #ccc;
				width: 90%;
				margin: 0 auto;

				&.last {
					border-bottom: 0rpx;
				}

				.left {
					flex: 1;
					color: #666;
					font-size: 28rpx;
					opacity: 0.8;

					&.last {
						flex: 2;
					}
				}

				.right {
					flex: 3;
					display: flex;
					justify-content: flex-end;
					align-items: center;

					&.last {
						flex: 2;
						margin-right: 44rpx;
					}

					.content {
						color: #ccc;
						font-size: 24rpx;
					}

					.icon {
						margin-left: 30rpx;
						width: 24rpx;
						height: 24rpx;

						img {
							width: 100%;
							height: 100%;
						}
					}
				}
			}
		}

		.PhoneLogin {
			width: 716rpx;
			height: 86rpx;
			background: #f0f0f0;
			border-radius: 44rpx 44rpx 44rpx 44rpx;
			opacity: 1;
			margin-left: 20rpx;
			text-align: center;
			line-height: 86rpx;
			font-size: 28rpx;
			color: #666;
			opacity: 0.8;
		}

	}
</style>